package oracle.v1;

import java.sql.*;

public class OracleJDBCv1 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.jdbc.Driver");
        String username="root";
        String password="";
        String url="jdbc:mysql://127.0.0.1:3306/mi?characterEncoding=UTF-8";
        Connection con=
                DriverManager.getConnection(url,username,password);
        System.out.println("测试Java链接数据对象："+con);

        String sql="select * from book";
        Statement st=con.createStatement();
        ResultSet rs=st.executeQuery(sql);
        System.out.println("------查询book表结果如下---------");
        while(rs.next()){  //取出每个字段记录【数据】
            //getInt("字段名")取字段名下类型
            int id=rs.getInt("id");
            //getString("字段名")取字段名下类型
            String author=rs.getString("author");
            String name=rs.getString("name");
            int price=rs.getInt("price");
            String date=rs.getString("date");
            int number=rs.getInt("number");
            String discount=rs.getString("discount");
            //打桩：打印作者记录
            System.out.println("作者："+author);
        }
    }
}
